package org.example.orders_learn;

import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;

import org.example.orders_learn.enums.Events;
import org.example.orders_learn.enums.Status;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.statemachine.StateMachine;

@SpringBootApplication
@Slf4j
public class OrdersLearnApplication implements CommandLineRunner {

    public static void main(String[] args) {
        SpringApplication.run(OrdersLearnApplication.class, args);
    }

    @Resource
    private StateMachine<Status, Events> stateMachine;


    @Override
    public void run(String... args) throws Exception {
        stateMachine.start();

//        Message<Events> message = MessageBuilder.withPayload(Events.PAY).build();
//        log.info("事件PAY信息");
//        boolean event = stateMachine.sendEvent(message);
//        log.info("创建{}",event);
//
//        message = MessageBuilder.withPayload(Events.SHIPPING).build();
//        log.info("事件SHIPPING信息");
//        event = stateMachine.sendEvent(message);
//        log.info("支付{}",event);
//
//        message = MessageBuilder.withPayload(Events.PAY).build();
//        log.info("事件PAY信息");
//        event = stateMachine.sendEvent(message);
//        log.info("创建{}",event);
    }
}
